﻿using UnityEngine;
using System.Collections;

public class CARBuyItem : MonoBehaviour {

	public GameObject m_WaitingBar;
	public UITexture  m_Circle;
	public UITexture  m_Texture;
	public int 		m_nID;
	bool m_bLoaded;

	// Use this for initialization
	void Start () {

	}
	
	// Update is called once per frame
	void Update () {
		m_Circle.transform.RotateAround (Vector3.back, Time.deltaTime * 2);

		if (m_bLoaded)
			m_WaitingBar.gameObject.SetActive(false);
	}

	public IEnumerator SetTexture()
	{
		VR_AR.AR_INFO arInfo = JsonDataRead.Instance.arData [JsonDataRead.Instance.curARID];
		Texture tex = JsonDataRead.Instance.FindTextureByUrl (arInfo.arImages[m_nID].sImageFilePath);

		if (tex == null) {
			WWW www = new WWW (JsonDataRead.Instance.DataPath + arInfo.arImages[m_nID].sImageFilePath);
			yield return www;
			m_Texture.mainTexture = www.texture;
			JsonDataRead.Instance.AddTexture(arInfo.arImages[m_nID].sImageFilePath, www.texture);
			m_bLoaded = true;
		} else {
			m_Texture.mainTexture = tex;
			m_bLoaded = true;
		}
	} 
}